﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCoreLenarn
{
    public class OrderConfig : IEntityTypeConfiguration<Order>
    {
        public void Configure(EntityTypeBuilder<Order> builder)
        {
            builder.ToTable("T_Orders");
            builder.Property(o => o.Address).IsUnicode();
            builder.Property(o => o.Name).IsUnicode();
            builder.HasOne<Delivery>(o => o.Delivery).WithOne(d => d.Order)
                .HasForeignKey<Delivery>(d => d.OrderId);
        }
    }

    public class DeliveryConfig : IEntityTypeConfiguration<Delivery>
    {
        public void Configure(EntityTypeBuilder<Delivery> builder)
        {
            builder.ToTable("T_Delivery");
            builder.Property(d => d.CompanyName).IsUnicode().HasMaxLength(100);
            builder.Property(d => d.Number).HasMaxLength(50);
        }
    }
}
